package com.xiaotu.spider.guduo.pipeline;

import java.util.List;
import java.util.Map;

import com.xiaotu.common.model.GuDuoPublicOpinionDataModel;
import com.xiaotu.common.model.GuDuoRecordDataModel;
import com.xiaotu.common.util.UUIDUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 GuDuoRecordDataPipeline
 * @功能 骨朵网大播放量
 */
public abstract class GuDuoRecordDataPipeline extends APipeline
{
    @SuppressWarnings("unchecked")
    @Override
    protected void doProcess(ResultItems resultItems, Task task)
    {
    	
    	//过程数据
    	List<GuDuoRecordDataModel> recordList = (List<GuDuoRecordDataModel>)resultItems.get(GuDuoRecordDataModel.class.getName());
        if (null != recordList && recordList.size()>0){
        	String key = getRedisKeyRecord();
        	for(GuDuoRecordDataModel m : recordList){
        		cacheHandler.hSet(key, m.getRedisKey(), m);
        	}
            cacheHandler.setCacheTimeout(key);
        }
        
        //舆情概况
        List<GuDuoPublicOpinionDataModel> publicOpinionList = (List<GuDuoPublicOpinionDataModel>)resultItems.get(GuDuoPublicOpinionDataModel.class.getName());
        if (null != publicOpinionList && publicOpinionList.size()>0){
        	String key = getRedisKeyPublicOpinion();
        	for(GuDuoPublicOpinionDataModel m : publicOpinionList){
        		cacheHandler.hSet(key, m.getRedisKey(), m);
        	}
            cacheHandler.setCacheTimeout(key);
        }
        
        //弹幕词云
        List<Map<String,Object>> worldCloudList = (List<Map<String,Object>>)resultItems.get("wordCloudAllList");
        if (null != worldCloudList && worldCloudList.size()>0){
        	String key = getRedisKeyWorldCloud();
        	for(Map<String,Object> m : worldCloudList){
        		cacheHandler.hSet(key, m.get("dataid")+"_"+UUIDUtils.getId()+"_"+m.get("name").toString(), m);
        	}
            cacheHandler.setCacheTimeout(key);
        }
        
        
    }

    //获取redis数据键
    public abstract String getRedisKeyRecord();
    public abstract String getRedisKeyPublicOpinion();
    public abstract String getRedisKeyWorldCloud();
}
